package com.baizhi.wd.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baizhi.wd.entity.User;
import com.baizhi.wd.service.UserService;
import com.baizhi.wd.service.UserServiceImpl;

public class LoginServlet2 {
	public void service(HttpServletRequest request,HttpServletResponse response) throws IOException {
	
	//1.设置响应内容类型
	response.setContentType("text/html;charset=GBK");
	//2.获取输出流
	PrintWriter out = response.getWriter();
	//3.使用输出流
	request.setCharacterEncoding("utf-8");
	String username = request.getParameter("username");
	String password = request.getParameter("password");
	
	out.println("<html>");
	out.println("<title>Version2.0</title>");
	out.println("<body>");
	
	UserService user = new UserServiceImpl();
	User ur = user.queryOne(username);
	if(user!=null&&ur.getUsername().equals(username)&&ur.getPassword().equals(password)){
		out.print("成功");
	}else{
		out.print("失败");
	}
	
	out.println("</body>");
	out.println("</html>");
	}
	
	

}
